﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OnlineCourse.Model;
using OnlineCourse.Model.Entity;
using OnlineCourse.Services;
using OnlineCourse.Services.Model;

namespace OnlineCourse.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class CommentController : ControllerBase
    {
        private readonly CommentService _home;
        public CommentController(ApplicationDbContext db)
        {
            _home = new CommentService(db);
        }
        /// <summary>
        ///添加一个反馈
        /// </summary>
        /// <param name="UserId"></param>
        /// <param name="SectionId"></param>
        /// <param name="Content"></param>
        /// <param name="TheAuthorContent"></param>
        /// <param name="Like"></param>
        /// <returns></returns>
        [HttpPost("Add")]
        public IActionResult Add(Guid UserId, Guid SectionId, string Content, string TheAuthorContent, int Like)
        {
            bool a = _home.Add(UserId, SectionId, Content, TheAuthorContent, Like);
            return Ok(a);
        }
        /// <summary>
        /// 删除一个反馈
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpDelete("Delete")]
        public IActionResult Delete(Guid Id)
        {
            bool a = _home.Delete(Id);
            return Ok(a);
        }
        /// <summary>
        /// 按照用户类型分页查询反馈
        /// </summary>
        /// <param name="UserId"></param>
        /// <param name="total"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("GetListByUserId")]
        public IActionResult QueryLists(Guid UserId, int total, int page, int pageSize)
        {
            var list = _home.QueryLists(UserId, out total, page, pageSize);
            return Ok(new { Total = total, Data = list });
        }
        /// <summary>
        /// 按照章节分页查询反馈
        /// </summary>
        /// <param name="SectionId"></param>
        /// <param name="total"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("GetListBySectionId")]
        public IActionResult QueryList(Guid SectionId, int total, int page, int pageSize)
        {
            var list = _home.QueryList(SectionId, out total, page, pageSize);
            var  a= new { Total = total, Data = list };
            return Ok(a);
        }
    }
}


